<template>
  <div class="public_main">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>{{$t('add.no44')}}</el-breadcrumb-item>
        <el-breadcrumb-item :to="{path:'/ruleList'}">{{$t('add.no45')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('rule.no29')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- ------------搜索查询栏开始-------------- -->
    <search 
      :searchData="searchData" 
      @search="search" 
      :searchRight="true"
    ></search>

    <div class="list_operation" >
      <el-button 
        type="primary" 
        @click="showAdd">
        {{$t('rule.no30')}}-{{ruleSetName}}
      </el-button>
    </div>

    <!-- -------------表单显示栏------------------------ -->
    <div class="table" >
      <template>
        <el-table :data="tableData" size="small" @selection-change="handleSelectionChange" v-loading="loadFlag">
          <el-table-column type="selection" :selectable="unSelect" width="55">
          </el-table-column>
          <el-table-column align="center" prop="id" label="ID">
          </el-table-column>
          <el-table-column align="center" prop="ruleType" :label="$t('rule.no13')">
          </el-table-column>
          <el-table-column align="center" prop="executeSort" :label="$t('rule.no31')">
          </el-table-column>
          <el-table-column align="center" prop="status" :label="$t('rule.no15')">
            <template slot-scope="scope">
              <span >{{scope.row.status==1?$t('loanMoney.isOverdue_options.no1'):$t('loanMoney.isOverdue_options.no2')}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="executeResult" :label="$t('rule.no32')">
            <template slot-scope="scope">
              <span >{{scope.row.executeResult==1?'Transfer':scope.row.executeResult==2?'Pass':scope.row.executeResult==-1?'Reject':''}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="conditionOne" :label="$t('rule.no33')">
          </el-table-column>
          <el-table-column align="center" prop="thresholdOne" :label="$t('rule.no34')">
          </el-table-column>
          <el-table-column align="center" prop="logicRelationOne" :label="$t('rule.no35')">
          </el-table-column>
          <el-table-column align="center" prop="conditionTwo" :label="$t('rule.no45')">
          </el-table-column>
          <el-table-column align="center" prop="thresholdTwo" :label="$t('rule.no46')">
          </el-table-column>
          <el-table-column align="center" prop="logicRelationTwo" :label="$t('rule.no35')">
          </el-table-column>
          <el-table-column align="center" prop="conditionThree" :label="$t('rule.no47')">
          </el-table-column>
          <el-table-column align="center" prop="thresholdThree" :label="$t('rule.no48')">
          </el-table-column>
          <el-table-column align="center" prop="exceuteLimit" :label="$t('rule.no36')">
          </el-table-column>
          <!-- <el-table-column fixed="right" align="center" prop="operation" label="操作">
            <template slot-scope="scope">
              <span 
                v-if="$store.state.common.permiss.includes('RIGHT_RULE_ENGINE_EDIT')"
                class="table_opr"
                @click="modifyRule(scope.row)">
                修改
              </span>
            </template>
          </el-table-column> -->
        </el-table>
      </template>
    </div>

    <el-dialog :title="$t('rule.no29')" :visible.sync="dialogFlag" width="560" top="20vh">
      <p class="mb20">{{$t('rule.no37')}}{{tableSelect.length}}{{$t('rule.no38')}}，{{$t('rule.no39')}}{{ruleSetName}}</p>
      <div class="button">
        <el-button type="primary" @click="submit">{{$t('public.no49')}}</el-button>
        <el-button type="primary" @click="detailClose">{{$t('public.no50')}}</el-button>
      </div>
    </el-dialog>


    <div class="foot"></div>

  </div>
</template>

<script>
export default {
  name: 'AddRuleEngine',
  data () {
    const searchData=[
      {
        type: 'input',
        label: 'rule.no12',
        attr: 'id',
        value: ''
      },{
        type: 'input',
        label: 'rule.no13',
        attr: 'ruleDesc',
        value: ''
      },{
        type: 'select',
        label: 'userSuggest.status',
        attr: 'configStatus',
        option: this.$store.state.options.ruleConfigstatus_option,
        value: '',
        langFlag: true,
      },{
        type: 'select',
        label: 'rule.no14',
        attr: 'executeResult',
        option: this.$store.state.options.ruleuserResult_option,
        value: '',
        langFlag: false,
      }]
    return {
      flag: true,
      loadFlag: true,
      sessionid: '',
      ruleSetName: '',
      ruleSetId: '',
      searchData: searchData,
      formInline: {},
      tableData: [],
      options1: [
        {label:'请选择',value:''},
        {id:1,label:'已配置',value:1},
        {id:0,label:'未配置',value:0},
      ],
      options2: [
        {label:'请选择',value:''},
        {id:1,label:'Reject',value:-1},
        {id:2,label:'Pass',value:2},
        {id:3,label:'Transfer',value:1},
      ],
      options3: [],
      userGradeOptions: [],
      tableSelect:[],
      dialogFlag: false,
    }
  },
  methods: {
    getTableData () { // 获取列表数据
      let option = {
        param: {
          ...this.formInline,
          ruleSetId: this.ruleSetId
        }
      }
      this.$axios.post(this.$action.risk_rule_base,option).then(res=>{
        this.flag = true;
        if(res.code==200){
          this.tableData = res.data;
        }
        this.loadFlag = false;
      })
    },
    search(search) { // 搜索
      this.formInline = {
        id: search.id,
        ruleSetId: this.ruleSetId,
        ruleDesc:search.ruleDesc,
        configStatus: search.configStatus,
        executeResult: search.executeResult,
      };
      this.getTableData();
    },
    handleSelectionChange (val) {
      this.tableSelect = val.map(value=>{
        return value = value.id
      })
    },
    unSelect (row) {
      return !row.configStatus
    },
    showAdd(){
      this.dialogFlag = true;
    },
    submit(){
      let option = {
        param: {
          ruleIds:this.tableSelect,
          id:this.ruleSetId
        }
      }
      this.$axios.post(this.$action.risk_rule_add,option).then(res=>{
        if (res.code == 200) {
          this.$globalMsg.success(this.$t('message.success'));
          this.getTableData();
          this.detailClose();
        } else {
          this.$globalMsg.error(res.message);
        }
      })
    },
    detailClose(){
      this.dialogFlag = false;
    }
  },
  watch: {
  },
  mounted () {
    this.sessionid = sessionStorage.getItem('sessionid')
    this.ruleSetId = this.$route.query.ruleSetId;
    this.ruleSetName = this.$route.query.ruleSetName;
    this.getTableData();
    
  }
}
</script>

<style scoped lang="scss">

</style>
